﻿///***************************************************************
/// 시  스  템 : Updms.Crd
/// 단위시스템 : CRD
/// 계      층 : Presentation Layer
/// 프로그램명 : Crd2013r
/// 파  일  명 : Crd2013r.aspx.cs
/// 설      명 : 미결제리스트
///***************************************************************
/// 수정ID 일자       이름     내용
///---------------------------------------------------------------
/// CH001  2008-08-07 송시명   최초 작성
///***************************************************************
using System;
using System.Data;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;

using SMFramework.Data;
using SMFramework.Utility;
using SMFramework.Web.UI.WebControls.SMGridView;

using Base.Dac;
using Updms.Crd.Exe;


namespace Updms.Crd
{
	public partial class Crd2013r : Updms.Common.BaseClass.PageBase
	{
		#region 전역영역

		//프로그램상수
		public static readonly string PID = "Crd2013r";
		public static readonly string gs_path_info = "/updms/Crd/" + PID + ".aspx";

		Global global = new Global();

		//검색
		protected string kw1 = "";	//카드
		protected string kw2 = "";	//기준일

		//메뉴 선택값
		protected string gs_sm = "";

		// 페이지모드
		private string gs_page_mode = "";

		#endregion

		#region Page_Load, OnPageLoad

		protected void Page_Load(object sender, EventArgs e)
		{
			SetInit();
			if (!Page.IsPostBack)
			{
				// 최초 화면 로딩시 처리해야 할 부분
				OnPageLoad();
			}
		}

		// OnPageLoad
		private void OnPageLoad()
		{
			SetLiterals(global.GetLabelInfoByPgmId(PID, LANG_SET));
			SetClientScript();
			SetCardInfo();
			SetSearchParameter();
		}

		#endregion

		#region InitializeComponent

		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);
			this.PreRender += new System.EventHandler(this.Page_PreRender);
		}

		#endregion

		#region SetClientScript

		private void SetClientScript()
		{
			txt_search_base_dt.Attributes.Add("onkeypress", "enterSearchOnPage(event)");
		}

		#endregion

		#region SetInit, SetSearchParameter

		//초기값설정
		private void SetInit()
		{
			lbl_search_flag.Text = "INIT";
			
			gs_sm = (Request.QueryString["sm"] == null || Request.QueryString["sm"].Trim().Length != 7)
					? global.GetDirDepth(PID) : Request.QueryString["sm"].ToString();
		}

		//검색파라미터
		private void SetSearchParameter()
		{
			string ls_card_cd = "";
			switch (lbl_search_flag.Text.Trim().ToUpper())
			{
				case "INIT":
					if (String.IsNullOrEmpty(Request.QueryString["kw1"]))	// url에 값이 없으면
					{
						for (int i = 0; i < cbl_search_card_cd.Items.Count; i++)
						{
							if (cbl_search_card_cd.Items[i].Selected == true)
							{
								ls_card_cd += cbl_search_card_cd.Items[i].Value + ",";
							}
						}
						kw1 = ls_card_cd.Substring(0, ls_card_cd.LastIndexOf(","));
					}
					else
					{
						kw1 = Server.UrlDecode(Request.QueryString["kw1"]);
						//kw1의 내용을 체크박스리스트에 바인딩
					}

					if (String.IsNullOrEmpty(Request.QueryString["kw2"]))	// url에 값이 없으면
					{
						if (String.IsNullOrEmpty(txt_search_base_dt.Text))
						{
                            kw2 = DateUtil.GetDayEx(0, "yyyy-MM-dd");	// 오늘
							txt_search_base_dt.Text = kw2;
						}
						else
						{
							kw2 = txt_search_base_dt.Text.Trim();
						}
					}
					else
					{
						kw2 = Server.UrlDecode(Request.QueryString["kw2"]);
						txt_search_base_dt.Text = kw2;
					}
					break;
				case "SEARCH":
					for (int i = 0; i < cbl_search_card_cd.Items.Count; i++)
					{
						if (cbl_search_card_cd.Items[i].Selected == true)
						{
							ls_card_cd += cbl_search_card_cd.Items[i].Value + ",";
						}
					}
					kw1 = ls_card_cd.Substring(0, ls_card_cd.LastIndexOf(","));
                    kw2 = String.IsNullOrEmpty(txt_search_base_dt.Text) ? DateUtil.GetDayEx(0, "yyyy-MM-dd") : txt_search_base_dt.Text.Trim();	// 오늘
					break;
			}
		}		

		#endregion

		#region 마스터 Method (SetCardInfo)

		//카드정보
		private void SetCardInfo()
		{
			DataSet lo_ds = new DataSet();
			Crd1010m_NT _Crd1010m_NT = new Crd1010m_NT();

			lo_ds.Merge(_Crd1010m_NT.GetCardInfoList("Y"));

			cbl_search_card_cd.Items.Clear();
			cbl_search_card_cd.DataSource = lo_ds;
			cbl_search_card_cd.DataMember = "UPDMS_CRD_INFO";
			cbl_search_card_cd.DataTextField = "Card_Nm";
			cbl_search_card_cd.DataValueField = "Card_Cd";
			cbl_search_card_cd.DataBind();

			if (cbl_search_card_cd.Items.Count > 0)
			{
				cbl_search_card_cd.Items[0].Selected = true;
			}
		}

		#endregion	

		#region CRUD (SelectProcess, SearchProcess)

		//조회
		private void SelectProcess()
		{
			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();
			
			//검색
			lo_dp.AddProperty("ls_card_cd", typeof(string), kw1);
			lo_dp.AddProperty("ls_base_dt", typeof(string), kw2);
			lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

			using (Crd2013r_NT _Crd2013r_NT = new Crd2013r_NT())
			{
				lo_ds.Merge(_Crd2013r_NT.GetNotPaymentList(lo_dp));

				if (!DataSetUtil.CheckRowCount(lo_ds, "UPDMS_CRD_REPORT"))
				{
					CallMsgBoxInAjax("MSG_ERR_111");	// 등록된 내용이 없습니다
				}

				GridView1.DataSource = lo_ds;
				GridView1.DataBind();
			}
		}	

		//검색
		private void SearchProcess()
		{
			gs_page_mode = "R";
			lbl_search_flag.Text = "SEARCH";
			SetSearchParameter();

			SelectProcess();
		}

		#endregion		

		#region Page_PreRender, ChangePageMode

		// Page_PreRender
		private void Page_PreRender(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				using (AccessCheck access = new AccessCheck())
				{
					//접근권한 체크
					if (!access.CheckPgmAccessGrant(PID, USER_ID, ACCESS_LOG_INFO))
					{
						Response.Redirect(URL_NO_AUTHORITY_REDIRECT_BASE);	//사용자의 권한은 요청하신 페이지를 볼 수 없습니다
					}
				}
			}
			ChangePageMode();
		}

		// ChangePageMode
		private void ChangePageMode()
		{
			switch (gs_page_mode)
			{
				case "":		// 처음 페이지로드시
					table_list_set.Visible = false;	// 리스트셋
					break;
				case "R":	// 검색버튼 클릭시
					table_list_set.Visible = true;	// 리스트셋
					break;
			}
			SetGridViewHeader(global.GetColumnListByPgmId(PID, LANG_SET));
		}

		#endregion

		#region GridView이벤트

		//RowDataBound
		protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
		{
			GridView gv = (GridView)sender;
			
			if (e.Row.RowType == DataControlRowType.DataRow)
			{
				//소계,총계
				switch (gv.DataKeys[e.Row.RowIndex].Values["Biz_Div"].ToString())
				{
					case "BA001": //일시불소계
						e.Row.Attributes.Add("class", "sub_total_v1");
						break;
					case "BA002": //현금서비스소계
						e.Row.Attributes.Add("class", "sub_total_v1");
						break;
					case "BA003": //할부소계
						e.Row.Attributes.Add("class", "sub_total_v1");
						break;
					case "BB004": //월별총계
						e.Row.Attributes.Add("class", "total_v2");
						break;
					case "BB001": //일시불총계
						e.Row.Attributes.Add("class", "total_v1");
						for (int i = 0; i < e.Row.Cells.Count; i++)
						{
							e.Row.Cells[i].Attributes.Add("class", "div_line_t_dbl");
						}
						break;
					case "BB002": //현금서비스총계
						e.Row.Attributes.Add("class", "total_v1");
						break;
					case "BB003": //할부총계
						e.Row.Attributes.Add("class", "total_v1");
						break;
					case "BB005": //총미결제액
						e.Row.Attributes.Add("class", "total_v3");
						break;
					default:
						//e.Row.Attributes.Add("class", "bg_white");
						break;
				}
			}

			//머지
			SMGridView sGv = new SMGridView(this.Page, ref GridView1);
			sGv.RowSpanGridView(GridView1, 0);//카드결제일
			sGv.RowSpanGridView(GridView1, 1);//카드명
			sGv.RowSpanGridView(GridView1, 2);//구분
			sGv.RowSpanGridView(GridView1, 3);//계정
		}		

		#endregion

		#region 버튼이벤트

		//검색
		protected void ibtn_search_Click(object sender, EventArgs e)
		{
			SearchProcess();
		}		

		//엑셀
		protected void ibtn_excel_Click(object sender, EventArgs e)
		{
			SetSearchParameter();

			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();

			lo_dp.AddProperty("ls_card_cd", typeof(string), kw1);
			lo_dp.AddProperty("ls_base_dt", typeof(string), kw2);
			lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

			using (Crd2013r_NT _Crd2013r_NT = new Crd2013r_NT())
			{
				lo_ds.Merge(_Crd2013r_NT.GetNotPaymentList(lo_dp));
			}
			string fileName = PID + "(" + global.GetMenuTitle(PID, LANG_SET) + ")";
			ExcelUtil.CreateExcelFileX(this.Page, fileName, lo_ds, SetExcelHeaderX(global.GetColumnListByPgmId(PID, LANG_SET)));
		}


		#endregion

	}
}
